package com.gxa.ehome.controller;

import com.gxa.ehome.pojo.SysUser;
import com.gxa.ehome.util.MapUtil;
import io.swagger.annotations.*;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.io.IOException;
import java.util.List;
import java.util.Map;

// Restful风格的请求方式

@Controller
@RequestMapping(value = "/sysUser2")
@Api(value = "描述restful风格的控制器",tags = "restfulController")
public class RestfulController {

    // 查询全部用户信息
    @GetMapping
    @ApiOperation(value = "查询全部系统用户信息",notes = "使用restful风格中,查询全部用户信息的操作方式,不带参数",tags = "getAll",response =
            List.class,httpMethod = "GET")
    public List<SysUser> getAll(){
        System.out.println("GET /ehome/sysUser2/");
        System.out.println("---------------------");
        return null;
    }

    // 查询指定id用户信息
    @GetMapping("/{id}")
    @ApiOperation(value = "通过id获取SysUser对象的方法",response = SysUser.class,httpMethod = "GET")
    @ApiImplicitParam(value ="用户id",required = true,paramType = "Integer",example = "1")
    public SysUser getById(@PathVariable("id")Integer id){
        System.out.println("GET /ehome/sysUser2/");
        System.out.println("id:"+id);
        System.out.println("---------------------");
        return null;
    }

    // 分页查询
    @GetMapping("/page/{page}/limit/{limit}")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "page",required = true,paramType = "Integer"),
            @ApiImplicitParam(name = "limit",required = true,paramType = "Integer")
    })
    public SysUser getByPage(@PathVariable("page")Integer page,@PathVariable("limit")Integer limit){
        System.out.println("GET /ehome/sysUser2/page/1/limit/10");
        System.out.println("page:"+page);
        System.out.println("limit:"+limit);
        System.out.println("---------------------");
        return null;
    }

    // 前端获取数据注入到SysUser对象上
    @PostMapping
    public Boolean reg(@RequestBody SysUser sysUser){
        System.out.println("POST /ehome/sysUser2/");
        System.out.println("jobNumber:"+sysUser.getJobNumber());
        System.out.println("---------------------");
        return false;
    }

   /* // 前端获取的数据注入到Map上(适合操作复杂数据类型中)
    @PostMapping
    public Boolean reg2(@RequestBody Map<String,Object> objectMap){
        System.out.println("POST /ehome/sysUser2/");
        System.out.println("jobNumber"+objectMap.get("jobNumber"));
        System.out.println("---------------------");
        return false;
    }*/

    // 修改sysUser对象的信息
    //后端只能用@RequestBody而不能用@RequestParam
    @PutMapping(/*"/id/{id}"*/)
    public void edit(@RequestBody @ApiParam(name = "sysUser",required = true,type = "SysUser") SysUser sysUser){
        System.out.println("PUT /ehome/sysUser2/");
        System.out.println("jobNumber:"+sysUser.getJobNumber());
        System.out.println("id:"+sysUser.getId());
        System.out.println("---------------------");
        return ;
    }

    @DeleteMapping("/id/{id}")
   // @DeleteMapping("/{id}")   如何和前端做好约定
    public  void delete(@PathVariable("id")Integer id){
        System.out.println("DELETE /ehome/sysUser2/");
        System.out.println("id:"+id);
        System.out.println("---------------------");
    }

    @DeleteMapping
    public  void delete(){
        System.out.println("DELETE /ehome/sysUser2/");
        System.out.println("---------------------");
    }
}
